<template>
  <div>
    <el-form
      ref="postForm"
      :model="postForm"
      :rules="rules"
      label-width="260px"
      label-suffix=":"
    >
      <sticky :z-index="10" :class-name="'sub-navbar ' + postForm.status">
        <el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="submitForm">
          保存
        </el-button>
      </sticky>

      <div style="padding: 15px">
        <el-row>
          <el-col :span="22">
            <el-form-item label="代理价格" style="width: 500px">
              <el-input v-model="postForm.vip1" />
            </el-form-item>
            <el-form-item label="加盟商价格" style="width: 500px">
              <el-input v-model="postForm.vip2" />
            </el-form-item>
            <el-divider />
            <el-form-item label="代理直推代理" style="width: 500px">
              <el-input v-model="postForm.vip1_1" />
              <span>代理推第1,2单, 比例%</span>
            </el-form-item>
            <el-form-item label="代理v1直推代理" style="width: 500px" v-if="false">
              <el-input v-model="postForm.vip1_n_1" />
              <span>代理(v1)推3+单, 比例%</span>
            </el-form-item>
            <el-form-item label="代理v1间推代理+" style="width: 500px">
              <el-input v-model="postForm.vip1_n_2" />
              <span>代理(v1)间推, 比例%</span>
            </el-form-item>
            <el-form-item label="加盟商直推代理" style="width: 500px">
              <el-input v-model="postForm.vip2_1" />
              <span>代理推第1,2单, 比例%</span>
            </el-form-item>
            <el-form-item label="加盟商v1直推代理+" style="width: 500px" v-if="false">
              <el-input v-model="postForm.vip2_n_1" />
              <span>加盟商(v1)推3+单, 比例%</span>
            </el-form-item>
            <el-form-item label="加盟商v1间推代理" style="width: 500px">
              <el-input v-model="postForm.vip2_n_2" />
              <span>加盟商(v1)间推, 比例%</span>
            </el-form-item>
            <el-divider />
            <el-form-item label="直推加盟商" style="width: 500px">
              <el-input v-model="postForm.vip2_2" />%
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="加盟商推三返一" style="width: 500px">
              <el-input v-model="postForm.vip2_n" />
              <span>每第推3单返, 比例%</span>
            </el-form-item>
            <el-form-item label="消费积分" style="width: 500px">
              <el-input v-model="postForm.score" />
              <span>购物使用,不可提现, 比例%</span>
            </el-form-item>
            <el-divider />
            <el-form-item label="复购直推" style="width: 500px">
              <el-input v-model="postForm.repeat_1" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="复购间推" style="width: 500px">
              <el-input v-model="postForm.repeat_2" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="复购间推3" style="width: 500px">
              <el-input v-model="postForm.repeat_3" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="复购间推4" style="width: 500px">
              <el-input v-model="postForm.repeat_4" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="复购间推5" style="width: 500px">
              <el-input v-model="postForm.repeat_5" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="复购间推6" style="width: 500px">
              <el-input v-model="postForm.repeat_6" />
              <span>比例%</span>
            </el-form-item>
            <el-divider />
            <el-form-item label="感恩奖1" style="width: 500px">
              <el-input v-model="postForm.v1" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="感恩奖2" style="width: 500px">
              <el-input v-model="postForm.v2" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="感恩奖3" style="width: 500px">
              <el-input v-model="postForm.v3" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="感恩奖4" style="width: 500px">
              <el-input v-model="postForm.v4" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="感恩奖5" style="width: 500px">
              <el-input v-model="postForm.v5" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="感恩奖6" style="width: 500px">
              <el-input v-model="postForm.v6" />
              <span>比例%</span>
            </el-form-item>
            <el-form-item label="分红" style="width: 500px">
              <el-input v-model="postForm.profit" />
              <span>比例%</span>
            </el-form-item>
            <el-divider />
            <h3 style="padding-left: 150px">星级比例设置,%, 极差</h3>
            <el-form-item label="一星比例" style="width: 500px">
              <el-input v-model="postForm.s1" />
            </el-form-item>
            <el-form-item label="二星比例" style="width: 500px">
              <el-input v-model="postForm.s2" />
            </el-form-item>
            <el-form-item label="三星比例" style="width: 500px">
              <el-input v-model="postForm.s3" />
            </el-form-item>
            <el-form-item label="四星比例" style="width: 500px">
              <el-input v-model="postForm.s4" />
            </el-form-item>
            <el-form-item label="五星比例" style="width: 500px">
              <el-input v-model="postForm.s5" />
            </el-form-item>
            <el-form-item label="六星比例" style="width: 500px">
              <el-input v-model="postForm.s6" />
            </el-form-item>
            <el-divider />
            <h3 style="padding-left: 150px">星级推荐升级</h3>
            <el-form-item label="一星" style="width: 500px">
              <el-input v-model="postForm.up_1" />
              <span>推多少个加盟商</span>
            </el-form-item>
            <el-form-item label="二星" style="width: 500px">
              <el-input v-model="postForm.up_2" />
              <span>推多少个一星</span>
            </el-form-item>
            <el-form-item label="三星" style="width: 500px">
              <el-input v-model="postForm.up_3" />
              <span>推多少个二星</span>
            </el-form-item>
            <el-form-item label="四星" style="width: 500px">
              <el-input v-model="postForm.up_4" />
              <span>推多少个三星</span>
            </el-form-item>
            <el-form-item label="五星" style="width: 500px">
              <el-input v-model="postForm.up_5" />
              <span>推多少个四星</span>
            </el-form-item>
            <el-form-item label="六星" style="width: 500px">
              <el-input v-model="postForm.up_6" />
              <span>推多少个五星</span>
            </el-form-item>
          </el-col>
        </el-row>
      </div>

    </el-form>
  </div>
</template>

<script>
import Sticky from '@/components/Sticky'
import api from '@/api'
export default {
  name: 'SystemFlow',
  components: {
    Sticky
  },
  data() {
    return {
      postForm: {
        status: 'draft'
      },
      rules: {
      },
      loading: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    async fetchData() {
      const { data } = await api.member.fetchSet()
      this.postForm = Object.assign({}, data)
      this.postForm.status = 'publisher'
    },
    submitForm() {
      this.$refs.postForm.validate(validate => {
        if (validate) {
          this.loading = true
          api.member.saveSet({
            ...this.postForm
          }).then(response => {
            this.$notify({
              title: '成功',
              message: response.message || '保存成功',
              type: 'success',
              duration: 2000
            })
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
